import { Http } from "@/utils/request";
import { Toast } from "@/utils/toast";
import { delayTask } from "@/utils/timer";

const baseUrl = "/guider_didi";

export const note_header_api = (data: { uid: string }, showError = true) => {
  return Http.get<any>(`${baseUrl}/note/header`, data).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const note_list_api = (
  data: { type: number; status: number; uid: string } & MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData & { statistics: any }>(
    `${baseUrl}/note/list`,
    data
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const user_edit_intro_api = (
  data: { edit_intro: string },
  showError = true
) => {
  return Http.post(`${baseUrl}/user/edit_intro`, data).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const user_follow_api = (
  data: { follow_id: string | number; type: number },
  showError = true
) => {
  return Http.post(`${baseUrl}/user/follow`, data).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const my_follow_guider_api = (
  data: MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(
    `${baseUrl}/my/follow_guider`,
    data
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const my_follow_studio_api = (
  data: MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(
    `${baseUrl}/my/follow_studio`,
    data
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const my_follow_author_api = (
  data: MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(
    `${baseUrl}/my/follow_author`,
    data
  ).catch((error: Error) => {
    showError && delayTask(60, () => Toast.show(error.message));
    return Promise.reject(error);
  });
};

export const note_fans_api = (data: MiniApp.PagingQuery, showError = true) => {
  return Http.get<MiniApp.PagingData>(`${baseUrl}/note/fans`, data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};
